package risk.control.project.framework.base;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import risk.control.project.config.constant.SecretKey;
import risk.control.project.utils.aes.CBC_Encryption;
import risk.control.project.utils.response.ResponseUtils;

/**
 * 基础加解密类
 */
public abstract class BaseEncryption {

    private static final Logger logger = LoggerFactory.getLogger(BaseEncryption.class);

    //秘钥
    private static final String secretKey = SecretKey.Map.get("base_secret_key");

    //只要请求成功都加密返回
    protected static <T> String generateSucceed(T data) {
        String resp = ResponseUtils.generateSucceed(data);
        return CBC_Encryption.encrypt(secretKey, resp);
    }

    //只要请求成功都加密返回
    protected static <T> String generateFail(String des) {
        String resp = ResponseUtils.generateFail(des);
        return CBC_Encryption.encrypt(secretKey, resp);
    }

    //只要请求成功都加密返回
    protected static <T> String generateFailForCode(String code, String des) {
        String resp = ResponseUtils.generateFail(code, des);
        return CBC_Encryption.encrypt(secretKey, resp);
    }

    //只要请求成功都加密返回
    protected static <T> String generateFailForCode(String code, String des, T data) {
        String resp = ResponseUtils.generateFail(code, des, data);
        return CBC_Encryption.encrypt(secretKey, resp);
    }

    protected static String BaseDecrypt(String content) {
        return CBC_Encryption.decrypt(secretKey, content);
    }

}
